import request from "../request";
import type { getSearchListParams, setListRes } from "@/types/global";
/**
 * 分页查询全部退货原因 - params
 */
interface IReturnReasonListParams {
  pageNum: number;
  pageSize: number;
}

/**
 * 分页查询全部退货原因 - model
 */
interface IReturnReasonListModel {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: IReturnReasonList[];
}
/**
 *
 * /**
 * 退货原因列表
 */
interface IReturnReasonList {
  id: number;
  name?: string;
  sort: number;
  status: number;
  createTime: string;
}

/**
 * 添加退货原因 - params
 */
interface IReturnReasonCreateParams {
  id?: number;
  name?: string;
  sort: number;
  status: number;
  createTime?: string;
}

/**
 * 分页查询全部退货原因
 */
const APIReturnReasonList = (
  params?: IReturnReasonListParams
): Promise<IReturnReasonListModel> =>
  request.get("/returnReason/list", { params });

/**
 * 修改退货原因启用状态
 */
const APIReturnReasonUpdateStatus = (
  ids: string,
  status: number
): Promise<number> =>
  request.post("/returnReason/update/status", undefined, {
    params: { ids, status },
  });

// 格式
interface Data<T> {
  code: number;
  message: string;
  data: T;
}

/**
 * 获取单个退货原因详情信息
 */
const APIReturnReasonById = (
  id: number
): Promise<Data<IReturnReasonCreateParams>> =>
  request.get(`/returnReason/${id}`);

/**
 * 修改退货原因
 */
const APIReturnReasonUpdateById = (
  id: number,
  params: IReturnReasonCreateParams
): Promise<Data<number>> => request.post(`/returnReason/update/${id}`, params);

/**
 * 添加退货原因
 */
const APIReturnReasonCreate = (
  params: IReturnReasonCreateParams
): Promise<Data<number>> => request.post("/returnReason/create", params);

/**
 * 批量删除退货原因
 */
const APIReturnReasonDeleteById = (ids: string): Promise<Data<number>> =>
  request.post(`/returnReason/delete?ids=${ids}`);

export {
  APIReturnReasonList,
  APIReturnReasonUpdateStatus,
  APIReturnReasonById,
  APIReturnReasonUpdateById,
  APIReturnReasonCreate,
  APIReturnReasonDeleteById,
};
